/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wso.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import wso.dto.WsoOrder;
import wso.global.BaseDao;

/**
 *
 * @author Violet_Ink
 */
public class OrderDaoImpl extends BaseDao implements OrderDao {

    public void saveOrUpdateOrder(WsoOrder order) {
        saveOrUpdate(order);
    }

    public void deleteOrder(String orderid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("update WsoOrder ord set ord.isdeleted = true where ord.orderid = :orderid");
        query = session.createQuery(str.toString());
        query.setString("orderid", orderid);

        query.executeUpdate();
    }

    public WsoOrder[] getAllOrder() {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("from WsoOrder ord where ord.isdeleted = false");
        query = session.createQuery(str.toString());
        List orderList = query.list();
        WsoOrder[] result = new WsoOrder[orderList.size()];
        orderList.toArray(result);

        return result;
    }

    public WsoOrder getOrder(String orderid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();

        str.append("from WsoOrder ord where ord.orderid = :orderid and user.isdeleted = false");
        query = session.createQuery(str.toString());
        query.setString("orderid", orderid);

        return (WsoOrder) query.uniqueResult();
    }

}
